package com.zxy.study.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zxy.study.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/*
 *  @项目名：  study
 *  @包名：    com.zxy.study.adapter
 *  @文件名:   TextAdapter
 *  @创建者:   zhangxy
 *  @创建时间:  2018/7/9 17:40
 *  @描述：    TODO
 */
public class TextAdapter extends RecyclerView.Adapter<TextViewHolder> {

	List<String> data = new ArrayList<>();

	public TextAdapter(String[] strs) {
		data.addAll(Arrays.asList(strs));
	}

	public TextAdapter(List<String> data) {
		this.data = data;
	}

	public TextAdapter() {
	}

	@NonNull
	@Override
	public TextViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
		LayoutInflater inflater = LayoutInflater.from(parent.getContext());
		return new TextViewHolder(inflater.inflate(R.layout.item_text, parent, false));
	}

	@Override
	public void onBindViewHolder(@NonNull TextViewHolder holder, int position) {
		TextView tv = holder.itemView.findViewById(R.id.tv);
		tv.setText(data.get(position));
	}

	@Override
	public int getItemCount() {
		return data.size();
	}
}
